package com.huitone.gddw.controller.system;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.huitone.gddw.dao.entity.Menu;
import com.huitone.gddw.service.system.IMenuService;

/**
 * 菜单管理 控制器
 * @author wuluodan
 *
 */
@Controller
@RequestMapping(value="menu")
public class MenuController {

	private final static Logger LOGGER = Logger.getLogger(MenuController.class);
	
	@Autowired
	private IMenuService menuService;
	
	/**
	 * 获取所有的菜单数据
	 * @return List
	 */
	@ResponseBody
	@RequestMapping(value="getAll")
	public List<Menu> getAll() {
		try {
			return menuService.getAll();
		} catch (Exception e) {
			LOGGER.error("获取所有的菜单数据出现异常：" + e.getMessage(), e);
			return null;
		}
	}
	
	/**
	 * 获取角色所有菜单
	 * @param roleId 角色ID
	 * @return List<Menu>
	 */
	@ResponseBody
	@RequestMapping(value="getMenusByRole")
	public List<Menu> getMenusByRole(String roleId) {
		try {
			List<Menu> list = menuService.getMenusByRole(roleId);
			return list;
		} catch (Exception e) {
			LOGGER.error("获取角色所有菜单信息过程中出现异常：" + e.getMessage(), e);
			return null;
		}
	}
	
}
